package com.huangguolin.cloud.api.Class.control;

import com.huangguolin.cloud.api.Class.entity.ApiClassSearchEntity;
import com.huangguolin.cloud.api.Class.service.ApiClassService;
import com.huangguolin.cloud.mybatis.entity.PtClassEntity;
import com.huangguolin.cloud.mybatis.entity.PtUserEntity;
import com.huangguolin.cloud.mybatis.flexigrid.PagingEntity;
import com.huangguolin.cloud.mybatis.ztree.TransferEntity;
import com.huangguolin.cloud.spring.control.BaseController;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/Class")
public class ApiClassController extends BaseController{
    private Logger logger = LogManager.getLogger(this.getClass());
    @Resource
    private ApiClassService apiClassService;

    @RequestMapping("/queryClassList")
    public List<PtClassEntity> queryClassList(ApiClassSearchEntity entity, PagingEntity paging ){
        logger.info(paging);
        logger.info(entity);
        List<PtClassEntity> list = apiClassService.queryClassList(entity,paging);
        return list;
    }
    @RequestMapping("/queryClassTotal")
    public String queryClassTotal(ApiClassSearchEntity entity){
        logger.info(entity);
        Integer total = apiClassService.queryClassTotal(entity);
        return totalJSON(total);
    }
    @RequestMapping("/delete")
    public String delete(String classIds){
        logger.info("classIds"+classIds);
        //非必选参数需要校验
        if(classIds == null){
            return failJSON("class.delete.fail");
        }
        apiClassService.deleteClass(classIds);
        return successJSON("class.delete.success");
    }
    @RequestMapping("/addClass")
    public String addClass(String teacher,String className,String classprofile,String cover,String privacy,String classId,String creatTime,String classNumber){
        apiClassService.addClass(teacher,className,classprofile,cover,privacy,classId,creatTime,classNumber);
        return successJSON("class.add.success");
    }
    @RequestMapping("/query")
   public List<TransferEntity>  query() {
        List<TransferEntity> list = apiClassService.query();
        return list;
    }
}

